package com.xt.controller;

import com.xt.bean.PlatformResult;
import com.xt.bean.StudentScore;
import com.xt.dto.StudentScoreListSearchDto;
import com.xt.service.StudentScoreService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * Created by XT on 2018/5/4.
 */
@RestController
@RequestMapping("/studentScore")
public class StudentScoreController {

    @Autowired
    StudentScoreService sss;

    @ApiOperation(value = "新增/修改信息", notes = "新增/修改信息")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public PlatformResult insert(@ApiParam(required = true, name = "class", value = "StudentScore实体的字段名") @RequestBody StudentScore ss) {
        //检查参数

        sss.saveOrUpdateOne(ss);
        return PlatformResult.ok();
    }

    @ApiOperation(value = "删除信息", notes = "删除信息")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public PlatformResult delete(@ApiParam(required = true, name = "class", value = "StudentScore实体的字段名") @RequestBody StudentScore ss) {
        //检查参数
        sss.deleteOne(ss.getId());
        return PlatformResult.ok();
    }

    @ApiOperation(value = "根据id查", notes = "根据id查")
    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    public PlatformResult getById(@ApiParam(required = true, name = "id", value = "id") @RequestParam String id) {
        StudentScore c = sss.getById(id);
        return PlatformResult.ok(c);
    }

    @ApiOperation(value = "列表", notes = "查询列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public PlatformResult list(
            @ApiParam(required = true, name = "studentScoreListSearchDto", value = "StudentScoreListSearchDto") @RequestBody StudentScoreListSearchDto dto) {
        Page<StudentScore> page = sss.getPage(dto);
        return PlatformResult.ok(page);
    }

}
